package com.ljw.gulimall.member.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.ljw.common.utils.PageUtils;
import com.ljw.common.utils.R;
import com.ljw.gulimall.member.feign.OrderFeignService;
import com.ljw.gulimall.member.vo.OrderItemVo;
import com.ljw.gulimall.member.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class MemberWebController {

    @Autowired
    private OrderFeignService orderFeignService;

    @GetMapping("/memberOrder.html")
    public String memberOrderPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  Model model){
        //查出当前登入用户的的所有订单列表数据
        Map<String,Object> page = new HashMap<>();
        page.put("page", pageNum.toString());
        R r = orderFeignService.listWithItem(page);
        PageUtils pageUtils = r.getData("page", new TypeReference<PageUtils>() {
        });
        String string = JSON.toJSONString(pageUtils.getList());
        List<OrderVo> orderVos = JSON.parseObject(string, new TypeReference<List<OrderVo>>() {
        });
        model.addAttribute("orders", orderVos);
        return "orderList";
    }
}
